package com.stu.spring.context.chapter13.jms;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

public class JmsSender {

    public static void main(String[] args) throws Exception {
        ConnectionFactory factory = new ActiveMQConnectionFactory();
        Connection connection = factory.createConnection();
        Session session = connection.createSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);
        Destination destination = session.createQueue("my-queue");
        MessageProducer producer = session.createProducer(destination);
        for (int i = 0;i < 3;i++){
            TextMessage message = session.createTextMessage("大家好，这是一个测试！");
            Thread.sleep(3000);
            // 通过消息生产者发布消息
            producer.send(message);
        }

        session.commit();
        session.close();
        connection.close();
    }

}
